package com.xiaoyang.controller;

import com.xiaoyang.domain.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther XiaoYang
 * @DATE 2023/5/3-17:45
 */
@RestController
public class TestController {

    @GetMapping("testGet")
    public String testGet(String name){
        System.out.println(name);
        return "OK";
    }

    /**
     * post方式传参
     * 1、json
     * 核心 ： 在请求头header里 content-type = application/json;charset = utf-8
     * @param user
     * @return
     */
    @PostMapping("testPost1")
    public String testPost1(@RequestBody User user){
        System.out.println(user);
        return "OK";
    }

    /**
     * post方式传参
     * 2、表单
     * 核心 ： 在请求头header里 content-type = x-www-from-urlencoded;charset = utf-8
     * @param user
     * @return
     */
    @PostMapping("testPost2")
    public String testPost2(User user){
        System.out.println(user);
        return "OK";
    }

}
